package com.wutianyi.shiro;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Collection;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.UnknownSessionException;
import org.apache.shiro.session.mgt.eis.MemorySessionDAO;

public class MySqlSessionDaoImpl extends MemorySessionDAO {

	@Override
	public void update(Session session) throws UnknownSessionException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oops;

		try {
			oops = new ObjectOutputStream(baos);
			oops.writeObject(session);
			System.out.println("session size: " + baos.size());
		} catch (IOException e) {
			e.printStackTrace();
		}
		super.update(session);
	}

	@Override
	public void delete(Session session) {
		super.delete(session);
	}

	@Override
	public Collection<Session> getActiveSessions() {
		return super.getActiveSessions();
	}

	@Override
	protected Serializable doCreate(Session session) {
		return super.doCreate(session);
	}

	@Override
	protected Session doReadSession(Serializable sessionId) {

		return super.doReadSession(sessionId);
	}

}
